package com.cyl.wms.controller;

import com.cyl.wms.domain.Icqa;
import com.cyl.wms.pojo.query.AddrQuery;
import com.cyl.wms.pojo.query.IcqaQuery;
import com.cyl.wms.pojo.vo.IcqaVO;
import com.cyl.wms.service.IcqaService;
import com.cyl.wms.service.IcqaService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 盘点Controller
 *
 * @author zcc
 * @date 2022-08-05
 */
@Api("盘点接口列表")
@RestController
@RequestMapping("/wms/icqa")
public class IcqaController extends BaseController {
    @Autowired
    private IcqaService service;

    @ApiOperation("查询盘点列表")
    @PreAuthorize("@ss.hasPermi('wms:icqa:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<IcqaVO>> list(@RequestBody IcqaQuery query, Pageable page) {
        com.github.pagehelper.Page list = (com.github.pagehelper.Page) service.selectList(query, page);
        List<IcqaVO> list2 = this.service.convert2vo(list);
        return ResponseEntity.ok(new PageImpl<>(list2, page, list.getTotal()));
    }

    @ApiOperation("导出盘点列表")
    @PreAuthorize("@ss.hasPermi('wms:icqa:export')")
    @Log(title = "盘点", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<String> export(IcqaQuery query) {
        List<Icqa> list = service.selectList(query, null);
        ExcelUtil<Icqa> util = new ExcelUtil<>(Icqa.class);
        return ResponseEntity.ok(util.writeExcel(list, "盘点数据"));
    }

    @ApiOperation("获取盘点详细信息")
    @PreAuthorize("@ss.hasPermi('wms:icqa:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<Icqa> getInfo(@PathVariable("id") Long id) {
        return ResponseEntity.ok(service.selectById(id));
    }

    @ApiOperation("新增盘点")
    @PreAuthorize("@ss.hasPermi('wms:icqa:add')")
    @Log(title = "盘点", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody Icqa Icqa) {
        return ResponseEntity.ok(service.insert(Icqa));
    }

    @ApiOperation("修改盘点")
    @PreAuthorize("@ss.hasPermi('wms:icqa:edit')")
    @Log(title = "盘点", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody Icqa Icqa) {
        return ResponseEntity.ok(service.update(Icqa));
    }

    @ApiOperation("删除盘点")
    @PreAuthorize("@ss.hasPermi('wms:icqa:remove')")
    @Log(title = "盘点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResponseEntity<Integer> remove(@PathVariable Long[] ids) {
        return ResponseEntity.ok(service.deleteByIds(ids));
    }
}
